﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
 }
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        租车人：<input id="nickname" col="nickname" type="text" />
                    </li>
                    <li>
                        租车号：<input id="carordersn" col="carordersn" type="text" />
                    </li>
                    <li>
                        状态：<span id="status" col="status"></span>
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm hidden-xs" id="toolbar">
            <a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a>
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        $("#status").ysComboBox({ data: ys.getJson(@Html.Raw(typeof(car_status_enum).EnumToDictionaryString())) });

        initGrid();

    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/QixingManage/PrebookOrder/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                //{ field: 'car_order_sn', title: '租车号' },
                //{ field: 'nickname', title: '租车人' },
                //{ field: 'wx', title: '微信' },
                //{ field: '', title: '配送方式',formatter: function (value, row, index) {
                //    if (row.type == "@PreShiptWay.送货上门.ParseToInt()") {
                //            return "@PreShiptWay.送货上门";
                //    } else if (row.type == "@PreShiptWay.到店自取.ParseToInt()") {
                //           return "@PreShiptWay.到店自取";
                //    } else if (row.type == "@PreShiptWay.其他.ParseToInt()") {
                //           return "@PreShiptWay.其他";
                //    }
                //   }
                //},
                { field: 'UserName', title: '预约人' },
                { field: 'telephone', title: '联系电话' },
                //{
                //    field: 'brand_name', title: '租车品牌'
                //},
                //{ field: 'car_rental_addr', title: '租车地址' },
                //{ field: 'car_return_addr', title: '还车地址' },
                //{
                //    field: 'car_rental_time', title: '租车时间', formatter: function (value, row, index) {
                //        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                //    }
                //},
                //{
                //    field: 'car_return_time', title: '还车时间', formatter: function (value, row, index) {
                //        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                //    }
                //},
                { field: 'status', title: '状态' ,  formatter: function (value, row, index) {
                        if (row.status == "@car_status_enum.待签到.ParseToInt()") {
                                return "@car_status_enum.待签到";
                        } else if (row.status == "@car_status_enum.已签到.ParseToInt()") {
                                 return "@car_status_enum.已签到";
                        } else if (row.status == "@car_status_enum.已取消.ParseToInt()") {
                                 return "@car_status_enum.已取消";
                        } else if (row.status == "@car_status_enum.已过期.ParseToInt()") {
                                 return "@car_status_enum.已过期";
                        } 
                        else if (row.status == "@car_status_enum.已取车.ParseToInt()") {
                                 return "@car_status_enum.已取车";
                        } 
                        else if (row.status == "@car_status_enum.已还车.ParseToInt()") {
                                 return "@car_status_enum.已还车";
                        } 
                   }
                },
                { field: 'PreBookShopName', title: '预约门店' },
                { 
                    field: 'PreBookCarTypes', 
                    title: '预约车型',
                     align: 'center',
                     formatter: function (value, row, index) {
                         if (!ys.isNullOrEmpty(value)) {
                             let cartypes=JSON.parse(value);
                             let html= "";
                             for (let i = 0; i < cartypes.length; i++) { 
                                 html += cartypes[i].name + "\n";
                             }
                             return html;
                         }
                     }
                },
                { field: 'car_renters_number', title: '租车人数' },
                { 
                     field: 'CarUsesPeopleAverageHeight', 
                     title: '用车人平均身高',
                     align: 'center',
                     formatter: function (value, row, index) {
                         if (!ys.isNullOrEmpty(value)) {
                             return value + "cm";
                         }
                     }
                },
                {
                    field: 'PreBookCarReceiveTime', title: '取车时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                 {
                    field: 'create_time', title: '预约时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="#" onclick="PrebookOrderDetailForm(\'' + row.Id + '\')"><i class="fa fa-list-ul"></i>明细查看</a>');
                        return actions.join('');
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function PrebookOrderDetailForm(id)
    {
         ys.openDialog({
            title:'明细查看',
            content: '@Url.Content("~/QixingManage/PrebookOrder/PrebookOrderDetailForm")' + '?id=' + id,
            width: '768px',
            height: '550px',
            btn: [],
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? '编辑' : '添加',
            content: '@Url.Content("~/QixingManage/PrebookOrder/PrebookOrderForm")' + '?id=' + id,
            width: '768px',
            height: '550px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗？', function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/QixingManage/PrebookOrder/DeleteFormJson")' + '?ids=' + ids,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>
